package cn.shengchao.examstar.distribute.ohs.remote.rpc;

import cn.hutool.core.collection.CollUtil;
import cn.shengchao.examstar.distribute.infrastrure.po.DistributeOrderTask;
import cn.shengchao.examstar.distribute.infrastrure.service.DistributeOrderTaskService;
import cn.shengchao.examstar.rpc.distribute.DistributeOrderTaskApi;
import cn.shengchao.examstar.rpc.distribute.enums.DistributeOrderTaskStatusDataStatusEnum;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;

import java.util.List;

/**
 * @program: examstarapi
 * @description: 分销订单处理api
 * @author: Xiong weiqiang
 * @create: 2025-04-23 16:21
 */
@DubboService
@RequiredArgsConstructor
public class DistributeOrderTaskDubboApi implements DistributeOrderTaskApi {
    private final DistributeOrderTaskService distributeOrderTaskService;

    @Override
    public Boolean processOrderRefund(Long orderId) {
        List<DistributeOrderTask> distributeOrderTasks=distributeOrderTaskService.list(
                Wrappers.lambdaQuery(DistributeOrderTask.class)
                        .eq(DistributeOrderTask::getOrderId,orderId)
        );
        if (CollUtil.isNotEmpty(distributeOrderTasks)){
            return distributeOrderTaskService.changeDataStatus(distributeOrderTasks.stream().map(DistributeOrderTask::getId).toList(), DistributeOrderTaskStatusDataStatusEnum.STATUS_CANCEL);
        }
        System.out.println("未找到分销订单，无法执行退款");
        return false;
    }
}